<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:74:"D:\phpStudy\WWW\oa\public/../application/index\view\misspass\savepass.html";i:1516349697;}*/ ?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title>网站信息</title>
    <link rel="stylesheet" href="__CSS__/pintuer.css">
    <link rel="stylesheet" href="__CSS__/admin.css">
    <link rel="stylesheet" href="__STATIC__/css/layui.css">
    <script src="__STATIC__/layui.js"></script>
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/pintuer.js"></script>
</head>
<style>
    .div {
        text-align: left;
        width: 1080px;
        margin: auto
    }
</style>
<body class="bodys panel admin-panel">
<div>
    <div class="panel-head"><strong><span class="icon-pencil-square-o"></span>修改密码</strong>&emsp;<a
            style="color: #3a4bfb;font-weight: bold " href="javascript:history.go(-1)">返回上一步</a></div>
    <div style="width: auto; height: auto;text-align: center">
        <form class="layui-form" action="">
            <div style="margin-top: 3%;margin-bottom: 2%;margin-right: 4%" class="layui-form-item">
                <div style="padding-left: 1%" class="layui-inline">
                    <label style="float: left;margin-top: 3%" class="layui-form-lable">用户名：</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" lay-verify="required" type="text" name="ch_name" id="ch_name">
                    </div>
                </div>
            </div>
            <div style="margin-top: 2%;margin-bottom: 2%;margin-left: 6%" class="layui-form-item">
                <div style="padding-right: 1.5%" class="layui-inline">
                    <label style="float: left;margin-top: 3%" class="layui-form-lable">邮&emsp;箱：</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" lay-verify="required|email" type="text" name="email" id="email">
                    </div>
                    <p data-method="confirmTrans" class="layui-btn layui-btn-sm" style="float: right;margin-top: 1%" id="start_rand">点击获取验证码</p>
                </div>
            </div>
            <div class="layui-form-item">
                <div  class="layui-inline">
                    <label style="float: left;margin-top: 3%" class="layui-form-lable">验证码：</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" lay-verify="required|number" type="text" name="rand" id="rand">
                    </div>
                    <p data-method="confirmTrans" class="layui-btn layui-btn-sm" style="float: right;margin-top: 1%;" id="submit_rand">确定</p>
                </div>
            </div>
            <div id="div" style="margin-right: 5%;display: none" class="layui-form-item">
                <div class="layui-inline">
                    <label style="float: left;margin-top: 3%" class="layui-form-lable">输入新密码：</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" lay-verify="required|password" type="password" name="password" id="password">
                    </div>
                </div>
            </div>
            <div style="margin-left: 10%;margin-top: 5%" class="layui-form-item">
                <div id="submits_a" style="display: none" class="layui-input-block">
                    <button class="layui-btn"  name="submit"  lay-submit="" lay-filter="demo">立即添加
                    </button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
                <div id="submits_b" class="layui-input-block">
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

</body>
<script>
    layui.use('form',function () {
        var form =layui.form;
        //监听提交
        form.on('submit(demo)', function (datas) {
            var data = JSON.stringify(datas.field);
            var sub = '确定修改';
            //console.log(data);
            $.ajax({
                url: "<?php echo url('Misspass/savepass'); ?>",
                type: "post",
                data: {"data": data, 'sub': sub},
                dataType: "json",
                success: function (i) {
                    //console.log(i);
                    if (i) {
                        if (i == 1){
                            layer.msg("修改成功",{icon: 6});
                        }else {
                            layer.msg("密码与原密码不能相同",{icon: 5});
                        }
                    } else {
                        layer.msg('修改失败',{icon: 2})
                    }
                }
            });
            return false;
        });
        //自定义验证
        form.verify({
            number: [/^\d{4}$/, '验证码格式不正确']
        });
    });
    $(document).on("blur", "#email", function () {
        layui.use('layer',function () {
            //验证邮箱
            var layer = layui.layer;
            var email_a = $('#email').val();
            if (email_a){
                $.ajax({
                    type: "post",
                    url: "<?php echo url('Base/getEmail'); ?>",
                    data: {"email": email_a},
                    dataType: "json",
                    success: function (z) {
                        if (z) {
                            layer.tips('点击获取验证码', '#start_rand', {
                                tips: 1
                            });
                        } else {
                            layer.msg("邮箱格式不正确，请重新填写",{icon: 5})
                        }
                    }
                })
            }
        });
        //alert(email);

    });
    $(document).on("click", "#start_rand", function () {
        layui.use('layer',function () {
            var layer = layui.layer;
            /*生成并发送验证码*/
            var email_b = $('#email').val();
            var ch_name = $('#ch_name').val();
            var sub = $('#start_rand').html();
            if (!ch_name){
                layer.msg('请输入用户名',{
                    offset: 't',
                    anim: 6});
            }if (!email_b){
                layer.msg('请输入邮箱', {
                    offset: 't',
                    anim: 6
                });
            }if (email_b && ch_name){
                $.ajax({
                    url: "<?php echo url('Misspass/get_rand'); ?>",
                    type: "post",
                    data: {"email_b": email_b, 'submit_a': sub, 'ch_name': ch_name},
                    dataType: "json",
                    success: function (i) {
                        //alert(i);
                        console.log(i);
                        if (i == 1) {
                            layer.msg('验证码已发送至邮箱，5分钟有效', {
                                offset: 't',
                                anim: 6
                            });
                            //layer.msg("验证码已发送至邮箱，5分钟有效",{icon: 6});
                            //layer.tips('请填写验证码', '#rand');
                        }
                        else if (i == 2) {
                            //layer.msg('验证码已发送',{icon: 6});
                            layer.tips('请填写验证码', '#rand', {
                                tips: 1
                            });
                            //layer.tips('请填写验证码', '#rand');
                        } else {
                            layer.msg('请重新输入邮箱')
                        }
                    }
                })
            }
        });
    });
    $(document).on('click', '#submit_rand', function () {
        /*验证验证码*/
        layui.use('layer',function () {
            var layer = layui.layer;
            var rand = $('#rand').val();
            var ch_name = $('#ch_name').val();
            var email = $('#email').val();
            var submit_rand = $('#submit_rand').html();
            if (!ch_name){
                layer.msg('请输入用户名', {
                    offset: 't',
                    anim: 6
                });
            }if (!email){
                layer.msg('请输入邮箱', {
                    offset: 't',
                    anim: 6
                });
            }if (!rand){
                layer.msg('请输入验证码', {
                    offset: 't',
                    anim: 6
                });
            }if (rand && email && ch_name){
                $.ajax({
                    url: "<?php echo url('Misspass/verify_rand'); ?>",
                    type: "post",
                    data: {"rand": rand, 'submit_rand': submit_rand, 'user_email': email, 'ch_name': ch_name},
                    dataType: "json",
                    success: function (i) {
                        //alert(i);
                        //console.log(i);
                        if (i) {
                            //alert("请填写新密码");
                            $('#div').css("display", "block");
                            $('#submits_a').css("display", "block");
                            $('#submits_b').css("display", "none");
                        } else {
                            layer.msg('验证码错误')
                        }
                    }
                })
            }
        });
    });
    $(document).on('click', '#submit', function () {
        layui.use('layer',function () {
            var layer = layui.layer;
//提交修改数据并返回结果
            var rand = $('#rand').val();
            var ch_name = $('#ch_name').val();
            var email = $('#email').val();
            var password = $('#password').val();
            var submit = $('#submit').val();
            if (!ch_name){
                layer.msg('请输入用户名', {
                    offset: 't',
                    anim: 6
                });
            }if (!email){
                layer.msg('请输入邮箱', {
                    offset: 't',
                    anim: 6
                });
            }if (!rand){
                layer.msg('请输入验证码', {
                    offset: 't',
                    anim: 6
                });
            }if (!password){
                layer.msg('请输入新密码', {
                    offset: 't',
                    anim: 6
                });
            }if (rand && email && ch_name && password){
                $.ajax({
                    url: "<?php echo url('Myself/savepass'); ?>",
                    type: "post",
                    data: {"rand": rand, 'submit': submit, 'email': email, 'ch_name': ch_name, 'password': password},
                    dataType: "json",
                    success: function (i) {
                        console.log(i);
                        if (i) {
                            layer.msg("修改成功",{icon: 6});
                            window.setTimeout("window.location=\"<?php echo url('Login/index'); ?>\"", 2000);
                        } else {
                            layer.msg('修改失败',{icon: 2})
                        }
                    }
                })
            }
        });
    })
</script>

</html>